import { GlobalObj } from "../obj/GlobalObj";
import { PGCServer } from "../PGCServer";
import { GameTool } from "../tool/GameTool";

/**
 * 方便初始化
 */
export class FaceEditInit {
    faceEidt: FaceEdit;
    faceEditCls: any
    static MakeupEdit: any;
    
    static maleUrls = [ // 男
        "upload/svn/resource/nars/1/model/sh42avatar02_physique_01_head.lh",
        "threeDimen/2023_3_19/male.lh",
        "upload/svn/resource/animation/jc_f_idle03_nars/ma.lani"
    ];

    static faleUrls = [// 女
        "upload/svn/resource/nars/1/model/sh42avatar01_physique_01_head.lh",
        "threeDimen/2023_3_19/female.lh",
        "upload/svn/resource/animation/jc_f_idle03_nars/fa.lani"
    ]

    baseAvatarUrl:string = "upload/svn/resource/nars/1/ske/female.lh";
    configUrl:string = "threeDimen/config.json";
    static FaceEditLoader: any;

    constructor(faceEditCls: any) {
        this.faceEditCls = faceEditCls;
    }

    onUpdate() {
        this.faceEidt.updateMakeup();
    }

    /**
     * 
     * @param isFa 是否是女的
     * @param callback 回调
     */
    init(isFa:boolean,  callback: Laya.Handler) {
        

        let load = new FaceEditInit.FaceEditLoader();
        // /** 
        // * 开始加载
        // * @param headurl 头部模型url
        // * @param tempurl  基础骨架url
        // * @param configUrl  配置文件url
        // * @param defHead 默认头 url
        // * /
        //     load(headurl:string, tempurl:string, configUrl:string , defHead:string , complete:Handler){
        
        let defHead = PGCServer.ins.formatUrl(isFa?FaceEditInit.faleUrls[0] : FaceEditInit.maleUrls[0]);
        let headUrl = isFa?FaceEditInit.faleUrls[1] : FaceEditInit.maleUrls[1];
        let tempUrl = PGCServer.ins.formatUrl(this.baseAvatarUrl);
        let configUrl = GlobalObj.SERV_URL + this.configUrl;
        headUrl = GlobalObj.SERV_URL + headUrl;
        load.load(headUrl, tempUrl, configUrl, defHead, Laya.Handler.create(this, (edit1: any) => {

            this.faceEidt = edit1;
            FaceEditInit.MakeupEdit.__init__();
            // this.initMale();
            this.faceEidt.updateMakeup();
            callback && callback.runWith(this.faceEidt);

        }));

    }

    private test1(head: any, templete: any, femaleTextResource: any) {
        this.faceEidt = new this.faceEditCls(head, templete, femaleTextResource.data);
        FaceEditInit.MakeupEdit.__init__()
        // this.initMale();
        this.faceEidt.updateMakeup();
    }

    
}